package thread;

import java.util.Vector;

public class Tester {
	public static void main(String[] args) {
		Vector<Thread> tlist = new Vector<Thread>();
		int n = 5;
		int t = 1;

		if (t > n / 2) {
			System.out.println("Number of thread must be less than N/2 !!");
			return;
		}

		FactorialN fn = new FactorialN();

		int range = n / t;
		int x = 1;

		long start = System.currentTimeMillis();
		
		for (int i = 0; i < t; i++) {
			int y = x + range - 1;
			y = n - y >= range ? y : n;
			MultipleK th = new MultipleK(fn, x, y);
			th.start();
			tlist.add(th);
			System.out.println("New thread have started: " + x + " -> " + y);
			x += range;
		}

		for (Thread th : tlist)
			try {
				th.join();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		System.out.println("Fn = " + fn.result);
		System.out.println("Time = " + (System.currentTimeMillis() - start));

	}
}
